package dhee.wtqshopproject.dao;

import dhee.wtqshopproject.entity.OrderItem;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface OrderItemMapper {
    @Delete("DELETE FROM order_item WHERE order_id = #{orderId}")
    int deleteOrderItemsByOrderId(Integer orderId);
    // 根据订单ID查询订单项
    @Select("SELECT * FROM order_item WHERE order_id = #{orderId}")
    List<OrderItem> selectByOrderId(Integer orderId);

    // 插入订单项
    @Insert("INSERT INTO order_item (order_id, product_id, quantity, price) " +
            "VALUES (#{orderId}, #{productId}, #{quantity}, #{price})")
    int insertOrderItem(OrderItem orderItem);
}
